package edu.egypt.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import edu.egypt.helpers.PermissionsDbOperations;
import edu.egypt.model.Permission;

/**
 * Servlet implementation class PermissionsAjaxResponse
 */
public class PermissionsAjaxResponse extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PermissionsAjaxResponse() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String Rid=request.getParameter("id");
        ArrayList<Permission> allPermissions = null;
        HashMap<String,String> param=new HashMap<String,String>(); 
        allPermissions = PermissionsDbOperations.getSingletonInstance().getAllPermissionsStatus(Integer.valueOf(Rid));
        
		response.setContentType("application/json");
		PrintWriter out = response.getWriter();
		Gson g= new Gson();
		String gs=g.toJson(allPermissions);
		out.println(gs);
		out.flush();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

}
